package com.ss.android.common.view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AbsListView;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.Scroller;

import inline.ScreenshotListener;

public final class ScrollDownLayout extends FrameLayout {
    public ScrollDownLayout(@NonNull Context context) {
        super(context);
    }

    enum InnerStatus {
        INITIAL,
        OPENED,
        CLOSED,
        MOVING,
        SCROLLING
    }

    public enum Status {
        OPENED,
        CLOSED
    }


    public final AbsListView.OnScrollListener mAssociatedListViewListener = null;
    public View mAssociatedView;
    private float mLastDownX;
    private float mLastDownY;
    private float mLastX;
    private float mLastY;
    private boolean isEnable;
    private boolean isAllowHorizontalScroll;
    private boolean isDraggable;
    private boolean isAllowPointerIntercepted;
    private boolean isCurrentPointerIntercepted;
    private boolean isAutoComplete;
    private InnerStatus mCurrentInnerStatus;
    private int maxOffset;
    private int minOffset;

    public final void updateListViewScrollState(AbsListView absListView) {
        if (absListView.getChildCount() == 0) {
            this.setDraggable(true);
        } else {
            if (absListView.getFirstVisiblePosition() != 0 || absListView.getChildAt(0).getTop() != absListView.getPaddingTop()) {
                this.setDraggable(false);
            } else {
                this.setDraggable(true);
            }
        }
    }

    public final void updateAssociatedViewPadding() {
        if (this.mAssociatedView != null) {
            this.mAssociatedView.setPadding(
                    this.mAssociatedView.getPaddingLeft(),
                    this.mAssociatedView.getPaddingTop(),
                    this.mAssociatedView.getPaddingRight(),
                    this.minOffset);
        }
    }

    public final boolean canScrollVertically(int arg5) {
        if (arg5 > 0) {
            if (-this.getScrollY() <= this.minOffset) {
                return false;
            }
        } else if (-this.getScrollY() >= this.maxOffset) {
            return false;
        }
        return true;
    }

    public final void computeScroll() {
        Scroller scroller = null;
        if (!scroller.isFinished() && (scroller.computeScrollOffset())) {
            int currY = scroller.getCurrY();
            this.scrollTo(0, currY);
            if (currY == -this.minOffset || currY == -this.maxOffset) {
                scroller.abortAnimation();
            } else {
                this.invalidate();
            }

        }
    }

    public final Status getCurrentStatus() {
        Status status;
        switch (this.mCurrentInnerStatus) {
            case CLOSED:
                status = Status.CLOSED;
                break;
            case OPENED:
                status = Status.OPENED;
                break;
            default:
                status = Status.OPENED;
                break;
        }

        return status;
    }

    public final int getMaxOffset() {
        return this.maxOffset;
    }

    public final int getMinOffset() {
        return this.minOffset;
    }

    public final boolean onInterceptTouchEvent(MotionEvent arg7) {
        Scroller v4 = null;
        boolean v0 = false;
        if ((this.isEnable) && ((this.isDraggable) || this.mCurrentInnerStatus != InnerStatus.CLOSED)) {
            switch (arg7.getAction()) {
                case 0: {
                    this.mLastDownX = arg7.getX();
                    this.mLastDownY = arg7.getY();
                    this.mLastX = this.mLastDownX;
                    this.mLastY = this.mLastDownY;
                    this.isAllowPointerIntercepted = true;
                    this.isCurrentPointerIntercepted = false;
                    if (v4.isFinished()) {
                        return v0;
                    }

                    v4.forceFinished(true);
                    this.mCurrentInnerStatus = InnerStatus.MOVING;
                    this.isCurrentPointerIntercepted = true;
                    return true;
                }
                case 2: {
                    if (!this.isAllowPointerIntercepted) {
                        return v0;
                    }

                    if (this.isCurrentPointerIntercepted) {
                        return true;
                    }

                    int v2 = ((int) (arg7.getY() - this.mLastY));
                    int v3 = ((int) (arg7.getX() - this.mLastX));
                    if (Math.abs(v2) < 10) {
                        return v0;
                    }

                    if (Math.abs(v2) < Math.abs(v3) && (this.isAllowHorizontalScroll)) {
                        this.isAllowPointerIntercepted = false;
                        this.isCurrentPointerIntercepted = false;
                        return v0;
                    }

                    if (this.mCurrentInnerStatus == InnerStatus.CLOSED) {
                        if (v2 < 0) {
                            return v0;
                        }
                    } else if (this.mCurrentInnerStatus == InnerStatus.OPENED && v2 > 0) {
                        return v0;
                    }

                    this.isCurrentPointerIntercepted = true;
                    return true;
                }
                case 1:
                case 3: {
                    label_32:
                    this.isAllowPointerIntercepted = true;
                    this.isCurrentPointerIntercepted = false;
                    if (this.mCurrentInnerStatus != InnerStatus.MOVING) {
                        return v0;
                    }

                    v0 = true;
                    return v0;
                }
            }

            return v0;
        }
        return v0;
    }

    public final boolean onTouchEvent(MotionEvent event) {
        int v4;
        GestureDetector gestureDetector = null;
        boolean v1 = false;
        if (this.isCurrentPointerIntercepted) {
            gestureDetector.onTouchEvent(event);
            switch (event.getAction()) {
                case 0: {
                    this.mLastDownY = event.getY();
                    return true;
                }
                case 2: {
                    int v0_1 = ((int) (event.getY() - this.mLastDownY));
                    v0_1 = Math.min(Math.abs(v0_1), 30) * (((int) Math.signum(((float) v0_1))));
                    if (v0_1 <= 0 && this.getScrollY() >= -this.minOffset) {
                        return true;
                    }

                    if (v0_1 >= 0 && this.getScrollY() <= -this.maxOffset) {
                        return true;
                    }

                    this.mCurrentInnerStatus = InnerStatus.MOVING;
                    v0_1 = this.getScrollY() - v0_1;
                    if (v0_1 >= -this.minOffset) {
                        this.scrollTo(0, -this.minOffset);
                    } else if (v0_1 <= -this.maxOffset) {
                        this.scrollTo(0, -this.maxOffset);
                    } else {
                        this.scrollTo(0, v0_1);
                    }

                    this.mLastDownY = event.getY();
                    v1 = true;
                    return v1;
                }
                case 1:
                case 3: {
                    if (this.mCurrentInnerStatus == InnerStatus.MOVING) {
                        if (this.isAutoComplete) {
                            if ((((float) this.getScrollY())) > -((((float) (this.maxOffset - this.minOffset))) * 0.8f)) {
                                if (this.mCurrentInnerStatus != InnerStatus.CLOSED && this.maxOffset != this.minOffset) {
                                    v4 = -this.getScrollY() - this.minOffset;
                                    if (v4 != 0) {
                                        this.mCurrentInnerStatus = InnerStatus.SCROLLING;
                                        ((Scroller) null).startScroll(0, this.getScrollY(), 0, v4, Math.abs(v4 * 300 / (this.maxOffset - this.minOffset)) + 100);
                                        this.invalidate();
                                    }
                                }
                            } else if (this.mCurrentInnerStatus != InnerStatus.OPENED && this.maxOffset != this.minOffset) {
                                v4 = -this.getScrollY() - this.maxOffset;
                                if (v4 != 0) {
                                    this.mCurrentInnerStatus = InnerStatus.SCROLLING;
                                    ((Scroller) null).startScroll(0, this.getScrollY(), 0, v4, Math.abs(v4 * 300 / (this.maxOffset - this.minOffset)) + 100);
                                    this.invalidate();
                                }
                            }
                        }
                        return true;
                    }
                    return v1;
                }
            }

            return v1;
        }
        return v1;
    }

    public final void scrollTo(int x, int y) {
        super.scrollTo(x, y);
        if (this.maxOffset != this.minOffset) {
            if (y == -this.minOffset) {
                if (this.mCurrentInnerStatus != InnerStatus.CLOSED) {
                    this.mCurrentInnerStatus = InnerStatus.CLOSED;
                }
            } else if (y == -this.maxOffset && this.mCurrentInnerStatus != InnerStatus.OPENED) {
                this.mCurrentInnerStatus = InnerStatus.OPENED;
            }
        }
    }

    public final void setAllowHorizontalScroll(boolean isAllowHorizontalScroll) {
        this.isAllowHorizontalScroll = isAllowHorizontalScroll;
    }

    public final void setAllowPointerIntercepted(boolean isCurrentPointerIntercepted) {
        this.isCurrentPointerIntercepted = isCurrentPointerIntercepted;
    }

    public final void setAssociatedListView(AbsListView absListView) {
        if (this.mAssociatedView != null && ((this.mAssociatedView instanceof ListView))) {
            ((ListView) this.mAssociatedView).setOnScrollListener(null);
        }

        absListView.setOnScrollListener(this.mAssociatedListViewListener);
        this.updateListViewScrollState(absListView);
        this.mAssociatedView = absListView;
        this.updateAssociatedViewPadding();
    }

    public final void setAutoComplete(boolean isAutoComplete) {
        this.isAutoComplete = isAutoComplete;
    }

    public final void setDraggable(boolean isDraggable) {
        this.isDraggable = isDraggable;
    }

    public final void setEnable(boolean isEnable) {
        this.isEnable = isEnable;
    }

    public final void setMaxOffset(int maxOffset) {
        this.maxOffset = maxOffset;
    }

    public final void setMinOffset(int minOffset) {
        this.minOffset = minOffset;
        this.updateAssociatedViewPadding();
    }

    public final void setOnScrollChangedListener$3ee9b4b4(ScreenshotListener imageDemo) {
    }
}

